package com.sy.cloud.wechat.service;

import com.sy.cloud.wechat.ConstantsPlaceholder;
import com.sy.cloud.wechat.WeChatConfig;
import com.sy.cloud.wechat.entity.WeChatUserInfo;
import com.sy.cloud.wechat.utils.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by mac on 2017/12/29.
 */
@Service
@Slf4j
public class WXGetOpenIdService {

    @Resource
    AuthorizeService authorizeService;

    /**
     * 作用：生成可以获得code的url
     * @param
     * @param
     * @return
     */
    public String GetOpenidFromMp(String code,String appId, String secret){
        String apiUrl = WeChatConfig.getUrl("useraccesstoken.get")
                .replace(ConstantsPlaceholder.APPID, appId)
                .replace(ConstantsPlaceholder.SECRET, secret)
                .replace(ConstantsPlaceholder.CODE, code);
        String rep = HttpUtils.get(apiUrl);
        log.info(rep);
        return rep;

    }
}
